package com.youzi.tunnel.client.config;

import com.youzi.tunnel.common.Config;
import lombok.Data;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;

/**
 * @Author: youzi
 * @Date: 2023-04-10
 * @Description: 配置
 */
@Slf4j
@Data
public class ClientProperties {

    private static ClientProperties instance = null;
    private static Config config = null;

    private boolean isDebugger;
    private String clientId;   //客户端凭据
    private boolean sslEnable;  //是否启用SSL加密连接
    private String sslJksPath;  //SSL证书路径
    private String sslKeyStorePassword;  //SSL证书密码
    private String serverHost;  //服务器地址或域名
    private int serverPort;  //服务器端口


    public static ClientProperties getInstance() {
        if (config == null) {
            synchronized (Config.class) {
                if (config == null) {
                    config = Config.getInstance();
                    config.init(null);
                }
            }
        }
        if (instance == null) {
            synchronized (ClientProperties.class) {
                if (instance == null) {
                    instance = new ClientProperties();
                    if (config.getState()) {
                        instance.isDebugger = config.getBooleanValue("debugger.enable");
                        instance.clientId = config.getStringValue("client.id");
                        instance.serverHost = config.getStringValue("server.host");
                        instance.serverPort = config.getIntValue("server.port");
                        instance.sslEnable = config.getBooleanValue("ssl.enable");
                        instance.sslJksPath = config.getStringValue("ssl.jksPath");
                        instance.sslKeyStorePassword = config.getStringValue("ssl.keyStorePassword");
                    } else {
                        instance.isDebugger = false;
                        instance.clientId = "youzi247";
                        instance.serverHost = "61.243.3.19";
                        instance.serverPort = 5672;
                        instance.sslEnable = false;
                        instance.sslJksPath = null;
                        instance.sslKeyStorePassword = null;
                    }
                }
            }
        }

        return instance;
    }
}
